# *-*coding=utf-8*-*
import time

from dataclasses import dataclass

from base_m3u8 import DownLoad_M3U8


@dataclass
class Download(DownLoad_M3U8):
    def download_all_ts(self):
        self.download_all_ts2()


def main():
    # m3u8_url = 'https://newv1.xinliangfc.com/01yxkcGuyG.m3u8'
    # 使用系统变量修改代理, 可以让m3u8解析也经过代理
    # os.environ["http_proxy"] = "http://127.0.0.1:10809"
    # os.environ["https_proxy"] = "https://127.0.0.1:10809"
    # print(os.environ)
    m3u8_url = 'https://hls1-l3.xvideos-cdn.com/3194029736d04b60b7895285658afcf8187c2fad-1601434031/videos/hls/23/29/b1/2329b1e5beb47b9446edd1ef68c533b4/hls-720p.m3u8'
    m3u8_url = 'https://video.twimg.com/ext_tw_video/1356112578619924482/pu/pl/UvaYB-8XjjmMmyGL.m3u8?tag=10'
    m3u8_url = 'https://209zy.suyunbo.tv/2020/11/06/vGyOu0r1YRX4lSiw/playlist.m3u8'
    m3u8_url = 'https://nitter.fiat-tux.fr/video/2993A44A8FF87/https%3A%2F%2Fvideo.twimg.com%2Fext_tw_video%2F1387612665124560897%2Fpu%2Fpl%2F464x848%2FLqHnNeEo2ipzMCAV.m3u8'
    m3u8_url = 'https://meiju10.stboda.com/20200202/OsDnL9Wt/index.m3u8'
    # m3u8_url = 'https://vod3.jializyzm3u8.com/20210805/kTDxn5cl/index.m3u8'
    # file_name = '乔依琳风吟鸟唱第二套流出！含口交视频+套图！正片.mp4'
    m3u8_url = 'https://lajiao-bo.com/20190501/7UPULaKp/600kb/hls/index.m3u8'
    m3u8_url = 'https://hnzy.bfvvs.com/play/PdyMowdQ/index.m3u8'
    m3u8_url = 'https://cdn15.yzzy-tv-cdn.com/20230614/15570_974cca82/2000k/hls/index.m3u8'
    file_name = '忠臣藏外传之四谷怪谈'
    ts_path = "../tmp"
    out_path = r"C:\download\twitter"
    proxies = {
        'sock5': '127.0.0.1:10808',
        'http': '127.0.0.1:10809',
        'https': '127.0.0.1:10809'
    }
    proxies = {}
    headers = {
        #"Referer": "https://shayujx.com/",
        #"origin": "https://shayujx.com/",
        "Referer": "https://cdn15.yzzy-tv-cdn.com/share/d69aed2be954d4c17700d4a99d79e42a",
        "origin": "cdn15.yzzy-tv-cdn.com",
        "Host": "cdn15.yzzy-tv-cdn.com",
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36'
    }
    download_proxies = proxies
    download_headers = {
        #"Referer": "https://shayujx.com/",
        #"origin": "https://shayujx.com/",
        "Referer": "https://cdn15.yzzy-tv-cdn.com/share/d69aed2be954d4c17700d4a99d79e42a",
        "origin": "cdn15.yzzy-tv-cdn.com",
        "Host": "cdn15.yzzy-tv-cdn.com",
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 dingtalk-win/1.0.0 nw(0.14.7) DingTalk(4.6.39-Release.10) Mojo/1.0.0 Native AppType(release)',
    }

    start = time.time()
    M3U8 = Download(
        m3u8_url=m3u8_url,
        file_name=file_name,
        out_path=out_path,
        ts_path=ts_path,
        proxies=proxies,
        rm_ts=False,
        headers=headers,
        max_workers=1,
        download_headers=download_headers,
        download_proxies=download_proxies
    )
    M3U8.run()
    end = time.time()
    print('耗时:', end - start)


if __name__ == '__main__':
    main()
